package com.erdos.hyt.mall.controller;

import com.erdos.hyt.base.exception.BaseBizException;
import com.erdos.hyt.base.exception.ExceptionCode;
import com.erdos.hyt.base.model.HytResponse;
import com.erdos.hyt.base.model.ResponseResultHandler;
import com.erdos.hyt.mall.model.MallGoodsType;
import com.erdos.hyt.mall.service.MallGoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2017/4/5.
 */

@Api(value = "MallGoodsTypeController API")
@RestController
@RequestMapping(value = "/mall")
public class MallGoodsTypeController {

    public static Logger logger = LoggerFactory.getLogger(MallGoodsTypeController.class);

    @Autowired
    MallGoodsTypeService typeService;

    @ApiOperation(value="查询商城商品类型", notes="查询商城商品类型",httpMethod ="GET")
    @RequestMapping(value = "/mallGoodsType", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public HytResponse getMallGoodsTypeList(){
        HytResponse<List<MallGoodsType>> hytResponse = null;

        try {
            List<MallGoodsType> typeList = typeService.getAllGoodsType();
            hytResponse = ResponseResultHandler.handleSuccess(typeList);
        }catch (BaseBizException e){
            logger.info(e.getMessage(), e);
            return ResponseResultHandler.handleError(ResponseResultHandler.RES_FAIL, ExceptionCode.BASE_SYSWRONG.getMessage());
        }
        return hytResponse;
    }

}